package com.wms.oms.controller;

import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.common.core.web.page.TableDataInfo;
import com.wms.common.security.annotation.PreAuthorize;
import com.wms.oms.domain.MoveOrder;
import com.wms.oms.service.IMoveOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zzm
 * @date 2023/8/23
 * @desc
 */
@RestController
@RequestMapping("/move")
public class MoveOrderController extends BaseController {

    @Autowired
    private IMoveOrderService moveOrderService;


    /**
     * 查询调拨单列表
     */
    @PreAuthorize(hasPermi = "oms:moveOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(MoveOrder moveOrder)
    {
        startPage();
        List<MoveOrder> list = moveOrderService.selectMoveOrderList(moveOrder);
        return getDataTable(list);
    }


    /**
     * 获取调拨单详细信息
     */
    @PreAuthorize(hasPermi = "oms:checkOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        MoveOrder moveOrder =  moveOrderService.selectMoveOrderById(id);
        return AjaxResult.success(moveOrder);
    }


    /**
     * 新增调拨单
     */
    @PreAuthorize(hasPermi = "oms:moveOrder:add")
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody @Valid MoveOrder moveOrder)
    {
        return toAjax(moveOrderService.insertMoveOrder(moveOrder));
    }


    /**
     * 修改调拨单
     */
    @PreAuthorize(hasPermi = "oms:moveOrder:edit")
    @PostMapping(value = "update")
    public AjaxResult edit(@RequestBody @Valid MoveOrder moveOrder)
    {
        return toAjax(moveOrderService.updateMoveOrder(moveOrder));
    }


    /**
     * 调拨确认
     */
    @PreAuthorize(hasPermi = "oms:moveOrder:edit")
    @PostMapping(value = "confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id)
    {
        MoveOrder moveOrder = moveOrderService.selectMoveOrderById(id);
        return toAjax(moveOrderService.confirm(moveOrder));
    }


    /**
     * 删除调拨单
     */
    @PreAuthorize(hasPermi = "oms:moveOrder:remove")
    @PostMapping(value = "delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(moveOrderService.deleteMoveOrderByIds(ids));
    }

}
